function getYear(date) {
    if(date == undefined) var date = new Date();
    date.setDate(date.getDate());
    return date.getFullYear();
}

function getMonth(date) {
    if(date == undefined) var date = new Date();
    date.setDate(date.getDate());
    return date.getMonth() + 1;
}

function getDate(date) {
    if(date == undefined) var date = new Date();
    date.setDate(date.getDate());
    return date.getDate();
}

/**
 * 计算当前日期为周几
 * @param date 日期
 * @returns {*}
 */
function getDay(date){
    var week;
    if(date == undefined) var date = new Date();
    date.setDate(date.getDate());
    var day = date.getDay();
    var dateNum = date.getDate();
    var dateMonth = date.getMonth();
    //判断今天
    var now = new Date();
    var tomorrow = addDate(now,1);
    var aftertomorrow = addDate(now,2);
    if(now.getDay() == day && dateNum == now.getDate() && dateMonth == now.getMonth()) {
        week='今天';
        return week;
    }else if(tomorrow.getDay() == day && dateNum == tomorrow.getDate() && dateMonth == tomorrow.getMonth()){
        week='明天';
        return week;
    }else if(aftertomorrow.getDay() == day && dateNum == aftertomorrow.getDate() && dateMonth == aftertomorrow.getMonth()){
        week='后天';
        return week;
    }
    if(day==0) week="周日"
    if(day==1) week="周一"
    if(day==2) week="周二"
    if(day==3) week="周三"
    if(day==4) week="周四"
    if(day==5) week="周五"
    if(day==6) week="周六"
    return week;
}
/*时间格式化为Date*/
function changeType(strTime) {
    //转换成Data();
    var date= new Date(Date.parse(strTime.replace(/-/g,  "/")));
    return date;
}
/*添加天数*/
function addDate(date,days){
    var d=new Date(date);
    d.setDate(d.getDate()+days);
    var m=d.getMonth()+1;
    var strTime =  d.getFullYear()+'-'+m+'-'+d.getDate();
    return changeType(strTime);
}
/**
 * 指定前几天的日期
 * @param n 前几天
 * @param timeDate 指定日期
 * @returns {string|*}
 */
function getBeforeDate(n,timeDate){
    var n = n;
    if(timeDate == undefined) {
        var d = new Date();
    }else{
        var d = new Date(Date.parse(timeDate));
    }
    var year = d.getFullYear();
    var mon=d.getMonth()+1;
    var day=d.getDate();
    if(day <= n){
        if(mon>1) {
            mon=mon-1;
        }
        else {
            year = year-1;
            mon = 12;
        }
    }
    d.setDate(d.getDate()-n);
    year = d.getFullYear();
    mon=d.getMonth()+1;
    day=d.getDate();
    s = year+"-"+(mon<10?('0'+mon):mon)+"-"+(day<10?('0'+day):day);
    return s;
}
//计算两个时间的差 分钟数
function TimeDifference(time1,time2)
{
//定义两个变量time1,time2分别保存开始和结束时间

//判断开始时间是否大于结束日期
    if(time1>time2)
    {
        // alert("开始时间不能大于结束时间！");
        return 'exceed';
    }


//截取字符串，得到日期部分"2009-12-02",用split把字符串分隔成数组
    var begin1=time1.substr(0,10).split("-");
    var end1=time2.substr(0,10).split("-");


//将拆分的数组重新组合，并实例成化新的日期对象
    var date1=new Date(begin1[1] + - + begin1[2] + - + begin1[0]);
    var date2=new Date(end1[1] + - + end1[2] + - + end1[0]);


//得到两个日期之间的差值m，以分钟为单位
//Math.abs(date2-date1)计算出以毫秒为单位的差值
//Math.abs(date2-date1)/1000得到以秒为单位的差值
//Math.abs(date2-date1)/1000/60得到以分钟为单位的差值
    var m=parseInt(Math.abs(date2-date1)/1000/60);


//小时数和分钟数相加得到总的分钟数
//time1.substr(11,2)截取字符串得到时间的小时数
//parseInt(time1.substr(11,2))*60把小时数转化成为分钟
    var min1=parseInt(time1.substr(11,2))*60+parseInt(time1.substr(14,2));
    var min2=parseInt(time2.substr(11,2))*60+parseInt(time2.substr(14,2));


//两个分钟数相减得到时间部分的差值，以分钟为单位
    var n=min2-min1;


//将日期和时间两个部分计算出来的差值相加，即得到两个时间相减后的分钟数
    var minutes=m+n;
    return minutes;
}
//获取当前时间
function CurentTime()
{
    var now = new Date();
    var year = now.getFullYear();       //年
    var month = now.getMonth() + 1;     //月
    var day = now.getDate();            //日

    var hh = now.getHours();            //时
    var mm = now.getMinutes();          //分
    var ss = now.getSeconds();           //秒

    var clock = year + "-";

    if(month < 10)
        clock += "0";

    clock += month + "-";

    if(day < 10)
        clock += "0";

    clock += day + " ";

    if(hh < 10)
        clock += "0";

    clock += hh + ":";
    if (mm < 10) clock += '0';
    // clock += mm + ":";
    clock += mm;

    /*if (ss < 10) clock += '0';
    clock += ss;*/
    return(clock);
}

//将时间戳转为时间
function CurentPrivateTime(now)
{
    var now = new Date(now);
    var year = now.getFullYear();       //年
    var month = now.getMonth() + 1;     //月
    var day = now.getDate();            //日

    var hh = now.getHours();            //时
    var mm = now.getMinutes();          //分
    var ss = now.getSeconds();           //秒

    var clock = year + "-";

    if(month < 10)
        clock += "0";

    clock += month + "-";

    if(day < 10)
        clock += "0";

    clock += day + " ";

    // // if(hh < 10)
    // //     clock += "0";
    // //
    // // clock += hh + ":";
    // // clock += mm + ":";
    // // clock += mm;
    //
    // if (ss < 10) clock += '0';
    // clock += ss;
    return(clock);
}
